package com.smashcrush.client.gwt.client.editor;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.TextBox;
import com.smashcrush.client.gwt.util.WidgetUtil;

public class ScriptBuilderTab extends Composite {

	List<TextBox> parameterTextBoxes;

	FlexTable table;

	public ScriptBuilderTab() {
		
		HTML html = new HTML();
		
		parameterTextBoxes = new ArrayList<TextBox>();

		DockPanel dockPanel = new DockPanel();

		table = new FlexTable();
		dockPanel.add(table, DockPanel.CENTER);

		Anchor addParameterAnchor = new Anchor("[Add Parameter]");
		addParameterAnchor.addClickHandler(new ClickHandler() {

			@Override
			public void onClick(ClickEvent event) {
				addParameter();
			}
		});
		dockPanel.add(addParameterAnchor, DockPanel.NORTH);

		initWidget(dockPanel);
	}

	private void addParameter() {

		int size = parameterTextBoxes.size();

		TextBox textBox = new TextBox();

		table.setWidget(size, 0, WidgetUtil.createLabel("Name"));
		table.setWidget(size, 1, textBox);
		
		Anchor removeAnchor = new Anchor("[remove]");
		removeAnchor.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				
			}
		});
		table.setWidget(size, 2, removeAnchor);

		parameterTextBoxes.add(textBox);
	}

}
